package rcs34.android.Namedays;

import java.util.ArrayList;
import java.util.GregorianCalendar;

import android.text.Html;
import android.text.Spanned;

public class Oneday {
  private ArrayList<String> names = new ArrayList<String>();
  private int day;
  private int month;
  private boolean htmlSupport = false;
  
  public Oneday(GregorianCalendar _today, boolean _htmlSupport) {
    day=_today.get(GregorianCalendar.DAY_OF_MONTH);
    month=_today.get(GregorianCalendar.MONTH);
    htmlSupport = _htmlSupport;
  }
  
  public void addName(String _name) {
    names.add(_name);
  }
  
  public int getDay(){
  	return day;
  }
  
  public int getMonth(){
    return month;
  }
  
  public String getNames() {
    StringBuilder result = new StringBuilder();
    int size = names.size();
    for (int i = 0; i < size; i++) {
      result.append(names.get(i));
      if (i < (size - 1)) {
        result.append(", ");
      }
    }
    return result.toString();
  }
  
  private void htmlName(StringBuilder _sb, String _name) {
    //_sb.append("<a href=\"http://krestni-jmena.cz/vyznam/index.php?name=");
    _sb.append("<a href=\"http://krestni-jmena.cz/vyznam/index.php?name=");
    _sb.append(_name);
    _sb.append("\">");
    _sb.append(_name);
    _sb.append("</a>");
  }
  
  public Spanned getHtmlNames() {
    if (!htmlSupport) {
      return Html.fromHtml(getNames());
    } else {
      StringBuilder result = new StringBuilder();
      int size = names.size();
      for (int i = 0; i < size; i++) {
        htmlName(result, names.get(i));
        if (i < (size - 1)) {
          result.append(", ");
        }
      }
      return Html.fromHtml(result.toString());
    }
  }
  
  public boolean startsWith(String _constraint) {
    String constraint = _constraint.toUpperCase();
    for (int i = 0; i < names.size(); i++) {
      if (names.get(i).toUpperCase().startsWith(constraint)) {
        return true;
      }
    }
    return false;
  }
}
